import CryptoJS from "crypto-js";

/**
 * 加密
 */
export const encryptByBase64DesEcbPkcs7 = (text: string, key: string) => {
  const keyHex = CryptoJS.enc.Utf8.parse(key);
  const encrypted = CryptoJS.DES.encrypt(text, keyHex, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7,
  });
  return CryptoJS.enc.Base64.stringify(encrypted.ciphertext) as string;
};

/**
 * 解密
 */
// export const decryptByBase64DesEcbPkcs7 = (text: string, key: string) => {
//   const keyHex = CryptoJS.enc.Utf8.parse(key);
//   const decrypted = CryptoJS.DES.decrypt(text, keyHex, {
//     mode: CryptoJS.mode.ECB,
//     padding: CryptoJS.pad.Pkcs7
//   });
//   return decrypted.toString(CryptoJS.enc.Utf8) as string;
// };
